package com.mbbmap.map;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.TreeMap;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;

import com.classes.CaseOutlet;
import com.classes.Casemast;
import com.classes.CasemastFactory;
import com.classes.Interchange;
import com.classes.InterchangeFactory;
import com.classes.Notification;
import com.classes.NotificationFactory;
import com.classes.OutletFactory;
import com.classes.StatusmastFactory;
import com.mbbmap.app.home.SecUsersHome;
import com.mbbmap.app.manager.ConfigManager;
import com.mbbmap.security.action.CommonDispatchAction;
import com.mbbmap.security.dao.SecAccessDao;
import com.mbbmap.security.dao.SecGroupsDao;
import com.mbbmap.security.dao.SecUserDao;
import com.mbbmap.security.manager.UserManager;
import com.mbbmap.util.Constants;
import com.mbbmap.util.EncryptionHelper;

public class NewAppAction extends CommonDispatchAction {
	private int iApp0 = 0; //APP000
	private int iApp1 = 0; //APP001
	private int iApp2 = 0; //APP002
	private int iApp3 = 0; //APP003
	private int iApp4 = 0; //APP004
	private String iMod = "";
	private TreeMap<String, String> viewAccess;
	private static final String modApproval = "MOD001";
	private static final String modVendorPosForm = "MOD001,MOD003";
	private static final String CONFIG_FILE = "/system.properties";
	private static final java.util.Properties appCfg = new java.util.Properties();
	
	private void authorized(HttpServletRequest request){
		HttpSession session = request.getSession(false);
		@SuppressWarnings("unchecked")
		ArrayList<SecAccessDao> secGroupAccessList = (ArrayList<SecAccessDao>) session.getAttribute(Constants.LOGON_ACCESS_LIST);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		this.iApp0 = 0;
		this.iApp1 = 0;
		this.iApp2 = 0;
		this.iApp3 = 0;
		this.iApp4 = 0;
		this.iMod = "";
		
		for(int i=0;i<secGroupAccessList.size();i++){
			SecAccessDao secaccessDao = (SecAccessDao)secGroupAccessList.get(i);
			String strModuleCode  = secaccessDao.getModuleCode();
			if(strModuleCode.equals("APP000")){
				if(secaccessDao.getWriteFlag().equals("01")){
					this.iApp0 = 1;
				}
				
				if(secaccessDao.getReadFlag().equals("01")){
					this.iApp0 = 2;
				}
				
				if(secaccessDao.getUpdateFlag().equals("01")){
					this.iApp0 = 3;
				}
			}
			
			if(strModuleCode.equals("APP001")){
				this.iApp1 = 1;
			}
			
			if(strModuleCode.equals("APP002")){
				this.iApp2 = 1;
			}
			
			if(strModuleCode.equals("APP003")){
				this.iApp3 = 1;
			}
			
			if(strModuleCode.equals("APP004")){
				this.iApp4 = 1;
			}
			
			if(strModuleCode.startsWith("MOD")){
				this.iMod = strModuleCode;
			}
		}
		
		
		this.viewAccess = new TreeMap<String, String>();
		this.viewAccess.put("view_as", "checker"); 			// maker / approver / checker / admin
		this.viewAccess.put("tab_recommendation", "none");
		this.viewAccess.put("tab_document", "none");
		this.viewAccess.put("tab_vendor", "none");
		this.viewAccess.put("download_document", "none");
		
		if(this.iApp0 >= 3) {
			this.viewAccess.put("view_as", "approver"); 
			this.viewAccess.put("tab_recommendation", "edit");
		}
		
		if(this.iApp2 > 0) {
			this.viewAccess.put("tab_document", "edit");
		}
		
		if(this.iApp3 > 0) {
			this.viewAccess.put("download_document", "edit");
		}
		
		this.viewAccess.put("mode_code", "MOD001");
		
		
		String s_arr[] = null;
		ArrayList<String> mod_arr = new ArrayList<String>();
		
		s_arr = NewAppAction.modVendorPosForm.split(",");
		for(String s : s_arr){
			mod_arr.add(s);
		}
		
		if(mod_arr.contains(this.iMod)) {
			this.viewAccess.put("tab_vendor", "edit");
		}
		
	}
	
	public ActionForward init(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.init";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}
//			if(!isTokenValid(request)){
//				System.out.println("Token validation failed!");
//				session.invalidate();
//				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
//			}else{
//				resetToken(request);
//				System.out.println("Token validation passed!");
//			}
			
			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			this.authorized(request);
			
			nextPage="not_authorized";
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null) {
				String c_id = EncryptionHelper.decrypt(request.getParameter("c_id"));
				String m_id = EncryptionHelper.decrypt(request.getParameter("m_id"));
				int case_id = Integer.parseInt(c_id);
				int merchant_id = Integer.parseInt(m_id);
				
				String strEMerchant = (String) session.getAttribute(Constants.MERCHANT_KEY);
				
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				
				m_case.loadHistories(strEMerchant, 1);
				m_case.loadHistories(strEMerchant, 2);
				
				System.out.println("iMod => " + this.iMod);
				
				ArrayList<TreeMap<String, String>> statusAction = StatusmastFactory.getActionStatuses(m_case.getStatus(), this.iMod, 1);
				if(statusAction == null){
					json_error(StatusmastFactory.getMessage(), response);
					return null;
				}
				
				
				ArrayList<TreeMap<String, String>> statusAction2 = StatusmastFactory.getActionStatuses(m_case.getStatus2(), 2);
				if(statusAction2 == null){
					json_error(StatusmastFactory.getMessage(), response);
					return null;
				}
				
				if(statusAction2.isEmpty()) {
					statusAction2 = StatusmastFactory.getActionStatuses(m_case.getStatus2(), 3);
					if(statusAction2 == null){
						json_error(StatusmastFactory.getMessage(), response);
						return null;
					}
				}
				
				
				ArrayList<SecGroupsDao> groupList = this.userGroupList(request);
				TreeMap<String, ArrayList<SecUserDao>> groupUsers = new TreeMap<String, ArrayList<SecUserDao>>();
				
				for(SecGroupsDao ug : groupList){
					ArrayList<SecUserDao> userList = new ArrayList<SecUserDao>();
					if ((strEMerchant != null) && (!strEMerchant.equals(""))){
						userList = SecUsersHome.getInstance().findSecGroupUserList(strEMerchant, ug.getGroupCode());
					}
					
					groupUsers.put(ug.getGroupCode(), userList);
				}
				
				
				ArrayList<Notification> n_arr = NotificationFactory.getMyNotification(oSecUserDao.getLogonId(), case_id);
				if(n_arr == null){
					json_error(NotificationFactory.getMessage(), response);
					return null;
				}
				
				
				request.setAttribute("groupList", groupList);
				request.setAttribute("groupUsers", groupUsers);
				request.setAttribute("m_case", m_case);
				request.setAttribute("merchant_id", merchant_id);
				request.setAttribute("case_id", case_id);
				request.setAttribute("status_action", statusAction);
				request.setAttribute("status_action2", statusAction2);
				request.setAttribute("n_arr", n_arr);
				
				
				System.out.println("Case ID: " + case_id);
				System.out.println("Merchant ID: " + merchant_id);
				
				if(this.iApp0 > 0){
					nextPage="business_details";
				}
				
			} else {
				this.viewAccess.put("tab_recommendation", "none");
				
				if(this.iApp1 > 0){
					nextPage="business_details";
				}
			}
			
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}

	public ActionForward match_trace(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.match_trace";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null) {
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				request.setAttribute("m_case", m_case);
				
				
				this.authorized(request);
				
				nextPage="not_authorized";
				
				if(this.iApp0 > 0){
					nextPage="match_trace";
				}
				
			} else {
				nextPage="not_authorized";
			}
			
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}
	
	public ActionForward outlet_detail(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.outlet_detail";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		try {
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null) {
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
				
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				m_case.loadOutlets();
				
				request.setAttribute("merchant_id", merchant_id+"");
				request.setAttribute("case_id", case_id+"");
				request.setAttribute("m_case", m_case);
				request.setAttribute("view", "outlet_detail");
				
				this.authorized(request);
				
				if(m_case.getCreatedBy().equals(oSecUserDao.getLogonId())){
					this.viewAccess.put("view_as", "maker");
				}
				
				
				if(request.getParameter("o_id") != null) {
					int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("o_id")));
					
					OutletFactory o = new OutletFactory();
					CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
					if(c_outlet == null){
						System.out.println(o.getMessage());
						return null;
					}
					
					request.setAttribute("c_outlet", c_outlet);
					
					
					nextPage="not_authorized";
					
					if(this.iApp0 > 0){
						nextPage="outlet_detail";
					}
					
				} 
				else {
					
					try {
						InputStream stream = NewAppAction.class.getResourceAsStream(CONFIG_FILE);
						if (stream != null){
							appCfg.load(stream);
						} else {
							System.out.println("NewAppAction.outlet_detail Input Stream is NULL");
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
					
					
					String http_scheme = appCfg.getProperty("HTTP_SCHEME");
					String host_domain = http_scheme + "://" + request.getServerName();
					
					if(request.getServerPort() != 80 && request.getServerPort() != 443){
						host_domain += ":" + request.getServerPort();
					}
					
					host_domain += request.getContextPath();
					
					System.out.println("Redirect domain : " + host_domain);
					
					if(m_case.getOutlets().size() > 0){
						CaseOutlet co = (CaseOutlet) m_case.getOutlets().get(0);
						String redirect_to = host_domain + "/NewApp.do?dispatch=outlet_detail&m_id=" + EncryptionHelper.encryptEncodeURL(merchant_id+"") + "&c_id=" + EncryptionHelper.encryptEncodeURL(case_id+"") + "&o_id=" + EncryptionHelper.encryptEncodeURL(co.getOutlet().getId()+"");
						
						response.sendRedirect( response.encodeRedirectURL(redirect_to) );
						
						System.out.println(redirect_to);
						return null;
					
					} else {
						
						String redirect_to;
						
						if(this.viewAccess.get("view_as").equals("maker") == true || this.viewAccess.get("view_as").equals("admin") == true){
							redirect_to = host_domain + "/NewApp.do?dispatch=outlet_create&m_id=" + EncryptionHelper.encryptEncodeURL(merchant_id+"") + "&c_id=" + EncryptionHelper.encryptEncodeURL(case_id+"");
						} else {
							redirect_to = host_domain + "/NewApp.do?dispatch=init&m_id=" + EncryptionHelper.encryptEncodeURL((merchant_id+"") + "&c_id=" + EncryptionHelper.encryptEncodeURL(case_id+""));
						}
						
						response.sendRedirect( response.encodeRedirectURL(redirect_to) );
						
						System.out.println(redirect_to);
						return null;
					}
				}
				
			} else {
				nextPage="not_authorized";
			}
			
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
		} catch (Exception e) {
			return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
		}
	}
	
	public ActionForward outlet_create(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.outlet_create";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null) {
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
				
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				m_case.loadOutlets();
				
				
				
				if(m_case.getOutlets().size() > 0){
					CaseOutlet co = (CaseOutlet) m_case.getOutlets().get(0);
					request.setAttribute("c_outlet", co);
				}
				
				request.setAttribute("merchant_id", EncryptionHelper.encryptEncodeURL(merchant_id+""));
				request.setAttribute("case_id", EncryptionHelper.encryptEncodeURL(case_id+""));
				request.setAttribute("m_case", m_case);
				request.setAttribute("view", "outlet_create");
				
				this.authorized(request);
				
				if(m_case.getCreatedBy().equals(oSecUserDao.getLogonId())){
					this.viewAccess.put("view_as", "maker");
				}
				
				
				nextPage="not_authorized";
				
				if(this.iApp0 > 0){
					if(this.viewAccess.get("view_as").equals("maker") || this.viewAccess.get("view_as").equals("admin")){
						nextPage="outlet_detail";
					}
				}
				
				
				
			} else {
				nextPage="not_authorized";
			}
			
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}
	
	public ActionForward payment_info(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.payment_info";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null && request.getParameter("o_id") != null) {
				int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("o_id")));
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
				
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				m_case.loadOutlets(case_id);
				
				request.setAttribute("merchant_id", merchant_id);
				request.setAttribute("case_id", case_id);
				request.setAttribute("m_case", m_case);
				
				OutletFactory o = new OutletFactory();
				CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
				if(c_outlet == null){
					System.out.println(o.getMessage());
					return null;
				}
				
				request.setAttribute("c_outlet", c_outlet);

				try {
					InputStream stream = NewAppAction.class.getResourceAsStream(CONFIG_FILE);
					if (stream != null){
						appCfg.load(stream);
					} else {
						System.out.println("SubmitAppAction Input Stream is NULL");
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				
				String leading_zeroes_len = appCfg.getProperty("leading_zeroes_len");
				request.setAttribute("leading_zeroes_len", leading_zeroes_len);

				this.authorized(request);
				
				nextPage="not_authorized";
				
				if(this.iApp0 > 0){
					if(m_case.getCreatedBy().equals(oSecUserDao.getLogonId())){
						this.viewAccess.put("view_as", "maker");
					}
					
					if(m_case.getStatus().equals("PUT UP") == false && oSecUserDao.getGroupCode().startsWith("03")){
						nextPage="not_authorized";
					} else {
						nextPage="payment_info";
					}
				}
				
				
			} else {
				nextPage="not_authorized";
			}
			
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}
	
	public ActionForward statement_option(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.statement_option";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null && request.getParameter("o_id") != null) {
				int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("o_id")));
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
				
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				m_case.loadOutlets(case_id);
				
				request.setAttribute("merchant_id", merchant_id);
				request.setAttribute("case_id", case_id);
				request.setAttribute("m_case", m_case);
				
				OutletFactory o = new OutletFactory();
				CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
				if(c_outlet == null){
					System.out.println(o.getMessage());
					return null;
				}
				
				request.setAttribute("c_outlet", c_outlet);
				
			
				this.authorized(request);
				
				nextPage="not_authorized";
				
				if(this.iApp0 > 0){
					if(m_case.getCreatedBy().equals(oSecUserDao.getLogonId())){
						this.viewAccess.put("view_as", "maker");
					}
					
					nextPage="statement_option";
				}
				
			} else {
				nextPage="not_authorized";
			}
			
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}
	
	public ActionForward other_info(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.other_info";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null && request.getParameter("o_id") != null) {
				int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("o_id")));
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
				
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				m_case.loadOutlets(case_id);
				
				request.setAttribute("merchant_id", merchant_id);
				request.setAttribute("case_id", case_id);
				request.setAttribute("m_case", m_case);
				
				OutletFactory o = new OutletFactory();
				CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
				if(c_outlet == null){
					System.out.println(o.getMessage());
					return null;
				}
				
				request.setAttribute("c_outlet", c_outlet);
				
			
				this.authorized(request);
				
				nextPage="not_authorized";
				
				if(this.iApp0 > 0){
					if(m_case.getCreatedBy().equals(oSecUserDao.getLogonId())){
						this.viewAccess.put("view_as", "maker");
					}
					
					nextPage="other_info";
				}
				
			} else {
				nextPage="not_authorized";
			}
			
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}
	
	public ActionForward physical_address(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.physical_address";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null && request.getParameter("o_id") != null) {
				int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("o_id")));
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
				
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				m_case.loadOutlets(case_id);
				
				request.setAttribute("merchant_id", merchant_id);
				request.setAttribute("case_id", case_id);
				request.setAttribute("m_case", m_case);
				
				OutletFactory o = new OutletFactory();
				CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
				if(c_outlet == null){
					System.out.println(o.getMessage());
					return null;
				}
				
				request.setAttribute("c_outlet", c_outlet);
				
			
				this.authorized(request);
				
				nextPage="not_authorized";
				
				if(this.iApp0 > 0){
					if(m_case.getCreatedBy().equals(oSecUserDao.getLogonId())){
						this.viewAccess.put("view_as", "maker");
					}
					
					nextPage="physical_address";
				}
				
			} else {
				nextPage="not_authorized";
			}
			
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}
	
	public ActionForward payment_address(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.payment_address";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null && request.getParameter("o_id") != null) {
				int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("o_id")));
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
				
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				m_case.loadOutlets(case_id);
				
				request.setAttribute("merchant_id", merchant_id);
				request.setAttribute("case_id", case_id);
				request.setAttribute("m_case", m_case);
				
				OutletFactory o = new OutletFactory();
				CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
				if(c_outlet == null){
					System.out.println(o.getMessage());
					return null;
				}
				
				request.setAttribute("c_outlet", c_outlet);
				
			
				this.authorized(request);
				
				nextPage="not_authorized";
				
				if(this.iApp0 > 0){
					if(m_case.getCreatedBy().equals(oSecUserDao.getLogonId())){
						this.viewAccess.put("view_as", "maker");
					}
					
					nextPage="payment_address";
				}
				
			} else {
				nextPage="not_authorized";
			}
			
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}
	
	public ActionForward correspondence_address(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.correspondence_address";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null && request.getParameter("o_id") != null) {
				int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("o_id")));
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
				
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				m_case.loadOutlets(case_id);
				
				request.setAttribute("merchant_id", merchant_id);
				request.setAttribute("case_id", case_id);
				request.setAttribute("m_case", m_case);
				
				OutletFactory o = new OutletFactory();
				CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
				if(c_outlet == null){
					System.out.println(o.getMessage());
					return null;
				}
				
				request.setAttribute("c_outlet", c_outlet);
				
			
				this.authorized(request);
				
				nextPage="not_authorized";
				
				if(this.iApp0 > 0){
					if(m_case.getCreatedBy().equals(oSecUserDao.getLogonId())){
						this.viewAccess.put("view_as", "maker");
					}
					
					nextPage="correspondence_address";
				}
				
			} else {
				nextPage="not_authorized";
			}
			
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}
	
	public ActionForward mdr_form(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.mdr_form";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null && request.getParameter("o_id") != null) {
				int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("o_id")));
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
				
				String strEMerchant = (String) session.getAttribute(Constants.MERCHANT_KEY);
				
				// Validate User
				String logonUserId = (String) session.getAttribute(Constants.LOGINID);
				String countryCode = UserManager.getCountryCode(logonUserId);
				
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				m_case.loadOutlets(case_id);
				m_case.loadHistories(strEMerchant,1);
				
				boolean lockDownMDR = false;
				for(TreeMap<String, String> histLog : m_case.getHistories()) {
					if(histLog.get("action").equals("Approved. Request For MID Setup") || histLog.get("action").equals("Approved. To Issue Letter Of Acceptance")){
						lockDownMDR = true;
						break;
					}
				}
				
				request.setAttribute("merchant_id", merchant_id);
				request.setAttribute("case_id", case_id);
				request.setAttribute("m_case", m_case);
				request.setAttribute("countryCode", countryCode);
				
				OutletFactory o = new OutletFactory();
				CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
				if(c_outlet == null){
					System.out.println(o.getMessage());
					return null;
				}
				
				request.setAttribute("c_outlet", c_outlet);
				
			
				this.authorized(request);
				
				nextPage="not_authorized";
				
				if(this.iApp0 > 0){
					if(lockDownMDR == false && m_case.getCreatedBy().equals(oSecUserDao.getLogonId())){
						this.viewAccess.put("view_as", "maker");
					}
					
					
					if(m_case.getStatus().equals("PUT UP") == false && oSecUserDao.getGroupCode().startsWith("03")){
						nextPage="not_authorized";
					} else {
						nextPage="mdr_form";
					}
				}
				
			} else {
				nextPage="not_authorized";
			}
			
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}
	
	public ActionForward supporting_document(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.supporting_document";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null) {
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
				
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				m_case.loadDocuments();
				
				request.setAttribute("m_case", m_case);
				request.setAttribute("merchant_id", merchant_id);
				request.setAttribute("case_id", case_id);
				
				
				this.authorized(request);
				
				nextPage="not_authorized";
				
				if(this.iApp0 > 0 && this.iApp2 > 0){
					nextPage="supporting_document";
				}
				
			} else {
				nextPage="not_authorized";
			}
			
			
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}
	
	public ActionForward supporting_document_download(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.supporting_document_download";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			this.authorized(request);
			
			if(this.iApp0 <= 0 || this.iApp3 <= 0){
				nextPage="not_authorized";
				return mapping.findForward(nextPage);
			}
				
			if(request.getParameter("c_id") != null && request.getParameter("doc_id") != null) {
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				int doc_id = Integer.parseInt(request.getParameter("doc_id"));
				
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				
				TreeMap<String, String> docdata = m_case.getDocument(doc_id);
				if(docdata == null){
					return null;
				}
				
				byte[] docbytes = m_case.getDocumentBytes(doc_id);
				if(docbytes == null){
					return null;
				}
				
				
				ServletOutputStream outStream = response.getOutputStream();
				
				response.setContentType(docdata.get("type"));
				response.setContentLength(Integer.parseInt(docdata.get("length")));
				response.setHeader("Content-Disposition", "attachment; filename=\"" + docdata.get("name").toString() + "\"");
				
				outStream.write(docbytes);
				outStream.close();
				
				return null;
				
			} else {
				nextPage="not_authorized";
				return mapping.findForward(nextPage);
			}
			
	}
	
	public ActionForward supporting_document_upload(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.supporting_document_upload";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null) {
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
				
				try {
					// Create a factory for disk-based file items
					DiskFileItemFactory factory = new DiskFileItemFactory();

					// Configure a repository (to ensure a secure temp location is used)
					File repository = (File) getServlet().getServletContext().getAttribute("javax.servlet.context.tempdir");
					factory.setRepository(repository);

					// Create a new file upload handler
					ServletFileUpload upload = new ServletFileUpload(factory);

					// Parse the request
					List<FileItem> items = upload.parseRequest(request);
					Iterator<FileItem> iter = items.iterator();
					byte[] data = null;
					
					TreeMap<String, String> post = new TreeMap<String, String>();
					post.put("ref_no", "");
					
					while (iter.hasNext()) {
						FileItem item = iter.next();
						
						if (item.isFormField()) {
							if(item.getFieldName().equals("ref_no")){
								post.put("ref_no", item.getString());
							}
						} 
						else {
							String fileName = item.getName();
							String contentType = item.getContentType();
							long sizeInBytes = item.getSize();
							
							data = item.get();
							
							post.put("file_name", fileName);
							post.put("file_type", contentType);
							post.put("file_size", Long.toString(sizeInBytes));
						}
					}
					
					boolean ok = CasemastFactory.document_submit(case_id, post, data, oSecUserDao.getUserName());
					if(ok == false){
						json_error(CasemastFactory.getMessage() + "***", response);
						return null;
					}
					
					
					Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
					if(m_case == null){
						json_error(CasemastFactory.getMessage(), response);
						return null;
					}
					
					m_case.loadDocuments();
					
					
					request.setAttribute("m_case", m_case);
					request.setAttribute("merchant_id", merchant_id);
					request.setAttribute("case_id", case_id);
					
				} catch (Exception e){
					e.printStackTrace();
				}
				
				
				this.authorized(request);
				
				nextPage="not_authorized";
				
				if(this.iApp0 > 0 && this.iApp2 > 0){
					nextPage="supporting_document";
				}
				
			} else {
				nextPage="not_authorized";
			}
			
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}
	
	public ActionForward document_checklist(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.document_checklist";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null) {
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
				
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				request.setAttribute("m_case", m_case);
				request.setAttribute("merchant_id", merchant_id);
				request.setAttribute("case_id", case_id);
				
				this.authorized(request);
				
				nextPage="not_authorized";
				
				if(this.iApp0 > 0 && this.iApp2 > 0){
					nextPage="document_checklist";
				}
				
			} else {
				nextPage="not_authorized";
			}
			
			
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}
	
	public ActionForward recom_approval(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.recom_approval";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			this.authorized(request);
			
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null) {
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
				
				String strEMerchant = (String) session.getAttribute(Constants.MERCHANT_KEY);
		  		
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}	
				
				OutletFactory o = new OutletFactory();
				ArrayList<CaseOutlet> c_outlets = o.getCaseOutlets(case_id);
				if(c_outlets == null){
					System.out.println(o.getMessage());
					return null;
				}
			
				int outlet_id2 = 0;
				if(c_outlets.size() > 0) {
					outlet_id2 = (int)c_outlets.get(0).getOutlet().getId();
				}
				
				CaseOutlet c_outlet = null;
				
				if(request.getParameter("o_id") != null) {
					int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("o_id")));
					
					c_outlet = o.getCaseOutlet(case_id, outlet_id);
					if(c_outlet == null){
						System.out.println(o.getMessage());
						return null;
					}
					
					request.setAttribute("c_outlet", c_outlet);
				}
				else {
					if(outlet_id2 != 0) {
						int outlet_id = outlet_id2;
						
						c_outlet = o.getCaseOutlet(case_id, outlet_id);
						if(c_outlet == null){
							System.out.println(o.getMessage());
							return null;
						}
						
						request.setAttribute("c_outlet", c_outlet);
					}	
				}
				
				
				TreeMap<String, Integer> terminal_stat = new TreeMap<String, Integer>();
				terminal_stat.put("no_of_wired_terminal", 0);
				terminal_stat.put("no_of_wireless_terminal", 0);
				terminal_stat.put("no_of_mpos_terminal", 0);
				
				if(c_outlet != null) {
					if(c_outlet.getMidPOS().length() > 0 || c_outlet.getMidAMEX().length() > 0) {
						m_case.loadRecommendations(c_outlet.getMidPOS(), c_outlet.getMidAMEX());
						
						JSONArray recom = m_case.getRecommendations();
						
						for(int i=0; i<recom.size(); i++){
							JSONObject ro = (JSONObject) recom.get(i);
							
							int n = 0;
							
							if(ro.get("no_of_wired_terminal").toString().equals("") == false) {
								n = Integer.valueOf(ro.get("no_of_wired_terminal").toString());
								terminal_stat.put("no_of_wired_terminal", terminal_stat.get("no_of_wired_terminal") + n);
							}
							
							
							n = 0;
							
							if(ro.get("no_of_wireless_terminal").toString().equals("") == false) {
								n = Integer.valueOf(ro.get("no_of_wireless_terminal").toString());
								terminal_stat.put("no_of_wireless_terminal", terminal_stat.get("no_of_wireless_terminal") + n);
							}
							
							
							n = 0;
							
							if(ro.get("no_of_mpos_terminal").toString().equals("") == false) {
								n = Integer.valueOf(ro.get("no_of_mpos_terminal").toString());
								terminal_stat.put("no_of_mpos_terminal", terminal_stat.get("no_of_mpos_terminal") + n);
							}
						}
					}
				}
				
				request.setAttribute("terminal_stat", terminal_stat);
				
				
				m_case.loadHistories(strEMerchant, 1);
				
				System.out.println("iMod => " + this.iMod);
				
				ArrayList<TreeMap<String, String>> statusAction = StatusmastFactory.getActionStatuses(m_case.getStatus(), this.iMod, 1);
				if(statusAction == null){
					json_error(StatusmastFactory.getMessage(), response);
					return null;
				}
				
				
				ArrayList<SecGroupsDao> groupList = this.userGroupList(request);
				TreeMap<String, ArrayList<SecUserDao>> groupUsers = new TreeMap<String, ArrayList<SecUserDao>>();
				
				for(SecGroupsDao ug : groupList){
					ArrayList<SecUserDao> userList = new ArrayList<SecUserDao>();
					if ((strEMerchant != null) && (!strEMerchant.equals(""))){
						userList = SecUsersHome.getInstance().findSecGroupUserList(strEMerchant, ug.getGroupCode());
					}
					
					groupUsers.put(ug.getGroupCode(), userList);
				}
				
				
				request.setAttribute("groupList", groupList);
				request.setAttribute("groupUsers", groupUsers);
				request.setAttribute("merchant_id", merchant_id);
				request.setAttribute("case_id", case_id);
				request.setAttribute("m_case", m_case);
				request.setAttribute("c_outlets", c_outlets);
				request.setAttribute("status_action", statusAction);
				
				nextPage="not_authorized";
				
				if(this.iApp0 >= 3){
					String s_arr[] = null;
					ArrayList<String> mod_arr = new ArrayList<String>();
					
					s_arr = NewAppAction.modApproval.split(",");
					for(String s : s_arr){
						mod_arr.add(s);
					}
					
					if(mod_arr.contains(this.iMod)) {
						this.viewAccess.put("isApproval", "edit");
					}
					
					nextPage="recom_approval";
				}
				
			} else {
				nextPage="not_authorized";
			}
			
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}
	
	
	public ActionForward decline_letter(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.decline_letter";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null) {
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				//int merchant_id = Integer.parseIntEncryptionHelper.decrypt(request.getParameter("m_id")));
				
				
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				
				m_case.loadOutlets();
				
				ArrayList<CaseOutlet> outlet_arr = m_case.getOutlets();
				if(outlet_arr.size() <= 0){
					nextPage="not_authorized";
					return mapping.findForward(nextPage);
				}
				
				
				CaseOutlet c_outlet = m_case.getOutlets().get(0);
				JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getAddress());
				
				String address = "";
				
				if(obj != null) {
					address += obj.get("line_1").toString() + "\\\\par ";
					address += obj.get("line_2").toString() + "\\\\par ";
					address += obj.get("line_3").toString() + "\\\\par ";
					address += obj.get("line_4").toString() + "\\\\par ";
				}
				
				SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
				
				String p = this.getServlet().getServletContext().getRealPath("/resource/MAP-decline-letter.rtf");
				if (p==null || p.equalsIgnoreCase("")){
					p = "D:/Oracle/Middleware/user_projects/domains/mapsvr/servers/mapweb/tmp/_WL_user/mbbmap/cd9sqa/war/resource/MAP-decline-letter.rtf";
					System.out.println("p:"+p);
				}
				
				File file = new File(p);
				
			    BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));
			    
			    /*
			    // TEST CODE
			    String s = "{\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \\insrsid10774909 \\{$MAP_REF_NO\\}}";
				
			    temp = s.replaceAll("\\\\\\{\\$MAP_REF_NO\\\\\\}", "12345-W");
			    response.getWriter().print(temp);
			    */
			    
			    String line;
			    String temp;
			    String f_content = "";
			    while ((line = r.readLine()) != null) {
			    	temp = line.replaceAll("\\\\\\{\\$MAP_REF_NO\\\\\\}", "12345-W");
			    	temp = temp.replaceAll("\\\\\\{\\$MAP_DATE\\\\\\}", df.format(new Date()));
			    	temp = temp.replaceAll("\\\\\\{\\$MAP_MERCHANT_NAME\\\\\\}", m_case.getMerchant().getRegisteredName());
			    	temp = temp.replaceAll("\\\\\\{\\$MAP_MERCHANT_ADDR\\\\\\}", address);
			    	temp = temp.replaceAll("\\\\\\{\\$MAP_APPROVER\\\\\\}", oSecUserDao.getUserName());
			    	temp = temp.replaceAll("\\\\\\{\\$MAP_HEAD_OF_SECTION\\\\\\}", "Section Name");
			    	
			    	f_content += temp + "\r\n";
			    }
			    
			    r.close();
			    
			    byte[] b= f_content.getBytes();
			    
				ServletOutputStream outStream = response.getOutputStream();
				
				response.setContentType("text/rtf");
				response.setContentLength(f_content.length());
				response.setHeader("Content-Disposition", "attachment; filename=\"MAP-decline-letter.rtf\"");
				
				
				outStream.write(b);
				outStream.close();
				
			    
			    return null;
				
				
				
			} else {
				nextPage="not_authorized";
				return mapping.findForward(nextPage);
			}
			
	}
	
	public ActionForward offer_letter(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.offer_letter";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			String m_id = request.getParameter("m_id");
			String c_id = request.getParameter("c_id");
			if(c_id != null && c_id != null) {
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(c_id));
				//int merchant_id = Integer.parseIntEncryptionHelper.decrypt(request.getParameter("m_id")));

				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				
				m_case.loadOutlets();
				
				
				ArrayList<CaseOutlet> outlet_arr = m_case.getOutlets();
				if(outlet_arr.size() <= 0){
					nextPage="not_authorized";
					return mapping.findForward(nextPage);
				}
				
				
				CaseOutlet c_outlet = m_case.getOutlets().get(0);
				JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getAddress());
				
				String address = "";
				String address2 = "";
				String address3 = "";
				String address4 = "";
				
				if(obj != null) {
					/*address += obj.get("line_1").toString() + "\\\\par ";
					address += obj.get("line_2").toString() + "\\\\par ";
					address += obj.get("line_3").toString() + "\\\\par ";
					address += obj.get("line_4").toString() + "\\\\par ";*/
					
					address = obj.get("line_1").toString();
					address2 = obj.get("line_2").toString();
					address3 = obj.get("line_3").toString();
					address4 = obj.get("line_4").toString();
				}
				
				
				obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getOtherInfo());

				String officer_code = "";
				
				if(obj != null) {
					officer_code = obj.get("officer_code").toString();
				}

				
				
				obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
				
				String pos_visa_off_us = ""; 	//POS_Visa_Off_us
				String pos_master_off_us = ""; 	//POS_Master_Off_us
				String pos_visa_debit = "";		//POS_Visa_Debit
				String pos_master_debit = "";	//POS_Master_Debit
				String pos_amex_nett_disc_rate = "";	//POS_Amex_Nett_Disc_Rate
				String pos_eft_pos_atm = "";	//POS_EFT_POS_ATM
				String pos_maestro = "";		//POS_Maestro
				String pos_jcb = "";			//POS_JCB
				String pos_unionpay = "";		//POS_Union_Pay
				String dcc_rebate = "";			//DCC_Rebate
				
				String mo_visa_off_us = "";		//MO_Visa_Off_Us
				String mo_master_off_us = "";	//MO_Master_Off_us
				String mo_visa_debit = "";		//MO_Visa_Debit
				String mo_master_debit = "";	//MO_Master_Debit
				String mo_amex_nett_disc_rate = "";		//MO_Amex_Nett_Disc_Rate
				
				String to_visa_off_us = "";		//TO_Visa_Off_Us
				String to_master_off_us = "";	//TO_Master_Off_us
				String to_visa_debit = "";		//TO_Visa_Debit
				String to_master_debit = "";	//TO_Master_Debit
				String to_amex_nett_disc_rate = "";		//TO_Amex_Nett_Disc_Rate
				
				String rps_visa_off_us = "";	//RPS_Visa_Off_Us
				String rps_master_off_us = "";	//RPS_Master_Off_us
				String rps_visa_debit = "";		//RPS_Visa_Debit
				String rps_master_debit = "";	//RPS_Master_Debit
				String rps_amex_nett_disc_rate = "";		//RPS_Amex_Nett_Disc_Rate
				
				String ec_visa_off_us = "";		//EC_Visa_Off_Us
				String ec_master_off_us = "";	//EC_Master_Off_us
				String ec_visa_debit = "";		//EC_Visa_Debit
				String ec_master_debit = ""; 	//EC_Master_Debit
				String ec_amex_nett_disc_rate = "";		//EC_Amex_Nett_Disc_Rate
				
				String m2u_visa_off_us = "";		//M2U_Visa_Off_Us
				String m2u_master_off_us = "";	//M2U_Master_Off_us
				String m2u_visa_debit = "";		//M2U_Visa_Debit
				String m2u_master_debit = ""; 	//M2U_Master_Debit
				String m2u_amex_nett_disc_rate = "";		//M2U_Amex_Nett_Disc_Rate
				
				String e3_mdr = "";
				String e3_min = "";
				String e3_max = "";
				String e6_mdr = "";
				String e6_min = "";
				String e6_max = "";
				String e9_mdr = "";
				String e9_min = "";
				String e9_max = "";
				String e12_mdr = "";
				String e12_min = "";
				String e12_max = "";
				String e18_mdr = "";
				String e18_min = "";
				String e18_max = "";
				String e24_mdr = "";
				String e24_min = "";
				String e24_max = "";
				String e30_mdr = "";
				String e30_min = "";
				String e30_max = "";
				String e36_mdr = "";
				String e36_min = "";
				String e36_max = "";
				
				/*************************************************************/
				String pos_mydebit_local = "";	// POS, My Debit Local
				String pos_visa_debit_prepaid_local = "" ;	// POS, Visa Debit/prepaid Local
				String mo_visa_debit_prepaid_local = "";	// MO, Visa Debit/prepaid Local
				String to_visa_debit_prepaid_local = ""; 	// TO, Visa Debit/prepaid Local
				String rps_visa_debit_prepaid_local = "";	// RPS, Visa Debit/prepaid Local
				String ec_visa_debit_prepaid_local = ""; 	// EC, Visa Debit/prepaid Local
				String m2u_visa_debit_prepaid_local = ""; 	// M2U, Visa Debit/prepaid Local
				
				String pos_master_debit_prepaid_local = "" ;	// POS, master Debit/prepaid Local
				String mo_master_debit_prepaid_local = "";	// MO, master Debit/prepaid Local
				String to_master_debit_prepaid_local = ""; 	// TO, master Debit/prepaid Local
				String rps_master_debit_prepaid_local = "";	// RPS, master Debit/prepaid Local
				String ec_master_debit_prepaid_local = ""; 	// EC, master Debit/prepaid Local
				String m2u_master_debit_prepaid_local = ""; 	// M2U, master Debit/prepaid Local
				
				String pos_visa_local = ""; 	//POS, Visa Local
				String mo_visa_local = "" ; 	// MO, visa local
				String to_visa_local = "" ;		// TO, visa local
				String rps_visa_local = ""; 	// RPS, visa local
				String ec_visa_local = ""; 		// EC, visa local
				String m2u_visa_local = ""; 	// M2U, visa local
				
				String pos_master_local = ""; 	//POS, master Local
				String mo_master_local = "" ; 	// MO, master local
				String to_master_local = "" ;		// TO, master local
				String rps_master_local = ""; 	// RPS, master local
				String ec_master_local = ""; 		// EC, master local
				String m2u_master_local = ""; 	// M2U, master local
				
				String pos_amex_local = ""; 	//POS, amex Local
				String mo_amex_local = "" ; 	// MO, amex local
				String to_amex_local = "" ;		// TO, amex local
				String rps_amex_local = ""; 	// RPS, amex local
				String ec_amex_local = ""; 		// EC, amex local
				String m2u_amex_local = ""; 	// M2U, amex local
				
//				String pos_union_pay = "";		// Pos Union pay
				
//				String pos_visa_foreign = ""; 	// Pos Visa Foreign
//				String mo_visa_foreign = ""; 	// Mo Visa Foreign
//				String to_visa_foreign = ""; 	// To Visa Foreign
//				String rps_visa_foreign = ""; 	// RPS Visa Foreign
//				String ec_visa_foreign = ""; 	// Ec Visa Foreign
//				String m2u_visa_foreign = "";	// M2U Visa Foreign
//				
//				String pos_master_foreign = ""; 	// Pos master Foreign
//				String mo_master_foreign = ""; 	// Mo master Foreign
//				String to_master_foreign = ""; 	// To master Foreign
//				String rps_master_foreign = ""; 	// RPS master Foreign
//				String ec_master_foreign = ""; 	// Ec master Foreign
//				String m2u_master_foreign = "";	// M2U master Foreign
				
				String pos_amex_foreign = ""; 	// Pos amex Foreign
				String mo_amex_foreign = ""; 	// Mo amex Foreign
				String to_amex_foreign = ""; 	// To amex Foreign
				String rps_amex_foreign = ""; 	// RPS amex Foreign
				String ec_amex_foreign = ""; 	// Ec amex Foreign
				String m2u_amex_foreign = "";	// M2U amex Foreign
				
				if(obj != null) {
					pos_visa_off_us = obj.get("38").toString();
					pos_master_off_us = obj.get("54").toString();
					pos_visa_debit = obj.get("62").toString();
					pos_master_debit = obj.get("70").toString();
					pos_amex_nett_disc_rate = obj.get("307").toString();
					pos_eft_pos_atm = obj.get("78").toString();
					pos_maestro = obj.get("94").toString();
					pos_jcb = obj.get("102").toString();
					pos_unionpay = obj.get("110").toString();
					dcc_rebate = obj.get("167").toString();
					
					mo_visa_off_us = obj.get("40").toString();
					mo_master_off_us = obj.get("56").toString();
					mo_visa_debit = obj.get("64").toString();
					mo_master_debit = obj.get("72").toString();
					mo_amex_nett_disc_rate = obj.get("308").toString();
					
					to_visa_off_us = obj.get("41").toString();
					to_master_off_us = obj.get("57").toString();
					to_visa_debit = obj.get("65").toString();
					to_master_debit = obj.get("73").toString();
					to_amex_nett_disc_rate = obj.get("309").toString();
					
					rps_visa_off_us = obj.get("42").toString();
					rps_master_off_us = obj.get("58").toString();
					rps_visa_debit = obj.get("66").toString();
					rps_master_debit = obj.get("74").toString();
					rps_amex_nett_disc_rate = obj.get("310").toString();
					
					ec_visa_off_us = obj.get("43").toString();
					ec_master_off_us = obj.get("59").toString();
					ec_visa_debit = obj.get("67").toString();
					ec_master_debit = obj.get("75").toString();
					ec_amex_nett_disc_rate = obj.get("311").toString();
					
					m2u_visa_off_us = obj.get("44").toString();
					m2u_master_off_us = obj.get("60").toString();
					m2u_visa_debit = obj.get("68").toString();
					m2u_master_debit = obj.get("76").toString();
					m2u_amex_nett_disc_rate = obj.get("312").toString();
					
					e3_mdr = obj.get("246").toString();
					e3_min = obj.get("230").toString();
					e3_max = obj.get("238").toString();
					
					e6_mdr = obj.get("247").toString();
					e6_min = obj.get("231").toString();
					e6_max = obj.get("239").toString();
					
					e9_mdr = obj.get("248").toString();
					e9_min = obj.get("232").toString();
					e9_max = obj.get("240").toString();
					
					e12_mdr = obj.get("249").toString();
					e12_min = obj.get("233").toString();
					e12_max = obj.get("241").toString();
					
					e18_mdr = obj.get("250").toString();
					e18_min = obj.get("234").toString();
					e18_max = obj.get("242").toString();
					
					e24_mdr = obj.get("251").toString();
					e24_min = obj.get("235").toString();
					e24_max = obj.get("243").toString();
					
					e30_mdr = obj.get("252").toString();
					e30_min = obj.get("236").toString();
					e30_max = obj.get("244").toString();
					
					e36_mdr = obj.get("253").toString();
					e36_min = obj.get("237").toString();
					e36_max = obj.get("245").toString();
					
					/*************************************************************/
					pos_mydebit_local = obj.get("86").toString();
					
					pos_visa_debit_prepaid_local = obj.get("579").toString();
					mo_visa_debit_prepaid_local = obj.get("581").toString();
					to_visa_debit_prepaid_local = obj.get("582").toString();
					rps_visa_debit_prepaid_local = obj.get("583").toString();
					ec_visa_debit_prepaid_local = obj.get("584").toString();
					m2u_visa_debit_prepaid_local = obj.get("585").toString();

					pos_master_debit_prepaid_local = obj.get("603").toString();
					mo_master_debit_prepaid_local = obj.get("605").toString();
					to_master_debit_prepaid_local = obj.get("606").toString();
					rps_master_debit_prepaid_local = obj.get("607").toString();
					ec_master_debit_prepaid_local = obj.get("608").toString();
					m2u_master_debit_prepaid_local = obj.get("609").toString();
					
					
					pos_visa_local = obj.get("571").toString();
					mo_visa_local = obj.get("573").toString();
					to_visa_local = obj.get("574").toString();
					rps_visa_local = obj.get("575").toString();
					ec_visa_local = obj.get("576").toString();
					m2u_visa_local = obj.get("577").toString();
					
					
					pos_master_local = obj.get("595").toString();
					mo_master_local = obj.get("597").toString();
					to_master_local = obj.get("598").toString();
					rps_master_local = obj.get("599").toString();
					ec_master_local = obj.get("600").toString();
					m2u_master_local = obj.get("601").toString();
					
					pos_amex_local = obj.get("635").toString();
					mo_amex_local = obj.get("636").toString();
					to_amex_local = obj.get("637").toString();
					rps_amex_local = obj.get("638").toString();
					ec_amex_local = obj.get("639").toString();
					m2u_amex_local = obj.get("640").toString();
					
					
					pos_amex_foreign = obj.get("641").toString();
					mo_amex_foreign = obj.get("642").toString();
					to_amex_foreign = obj.get("643").toString();
					rps_amex_foreign = obj.get("644").toString();
					ec_amex_foreign = obj.get("645").toString();
					m2u_amex_foreign = obj.get("646").toString();
					
				}
				
				
				String trf = "";
				String no_of_wired_terminal = "";
				String no_of_wireless_terminal = "";
				String trf_wired = "";
				String trf_wireless = "";
				
				JSONObject recom = new JSONObject();
				
				if(c_outlet.getRecommendation().length() > 0){
					recom = (JSONObject)JSONValue.parse(c_outlet.getRecommendation());
					
					trf = (recom.get("trf") == null) ? "" : recom.get("trf").toString();
					no_of_wired_terminal = (recom.get("no_of_wired_terminal") == null) ? "" : recom.get("no_of_wired_terminal").toString();
					no_of_wireless_terminal = (recom.get("no_of_wireless_terminal") == null) ? "" : recom.get("no_of_wireless_terminal").toString();
					
					double n = 0;
					double m = 0;
					double p = 0;
					try {
						n = Double.parseDouble(no_of_wired_terminal);
						m = Double.parseDouble(trf);
						p = n * m;
						
						trf_wired = String.format("%0.2f", p);
						
					} catch (Exception e) {
						
					}
					
					
					n = 0;
					m = 0;
					p = 0;
					try {
						n = Double.parseDouble(no_of_wireless_terminal);
						m = Double.parseDouble(trf);
						p = n * m;
						
						trf_wireless = String.format("%0.2f", p);
						
					} catch (Exception e) {
						
					}
				}
				
				
				String best_practice = m_case.getBestPractice();
				String letter_template = "LO-MAP-v4.rtf";
				
				if(best_practice.equals("Best Practice for E-Commerce Merchant")) {
					letter_template = "LO-MAP-v4-ecommerce.rtf";
				}
				else if(best_practice.equals("Best Practice for Recurring Payment System (RPS) Merchant")) {
					letter_template = "LO-MAP-v4-rps.rtf";
				}
				else if(best_practice.equals("Best Practice for Mail Order Telephone Order (MO/TO) Merchant")) {
					letter_template = "LO-MAP-v4-moto.rtf";
				}
				else if(best_practice.equals("Best Practice for EzyPayment Merchant")) {
					letter_template = "LO-MAP-v4-ezypayment.rtf";
				}
				
				SimpleDateFormat df_1 = new SimpleDateFormat("d MMMMM yyyy");
				
				String p = this.getServlet().getServletContext().getRealPath("/resource/" + letter_template); // MAP-offer-letter-sample
				if (p==null || p.equalsIgnoreCase("")){
					p = "D:/Oracle/Middleware/user_projects/domains/mapsvr/servers/mapweb/tmp/_WL_user/mbbmap/cd9sqa/war/resource/" + letter_template;
					System.out.println("p:"+p);
				}

				File file = new File(p);
				
				if (!file.exists()) {
					p = "D:/app/mbbmap/mbbmap/resource/" + letter_template;
					file = new File(p);
				}
				
			    BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));
			    

			    String line;
			    String temp;
			    String f_content = "";
			    while ((line = r.readLine()) != null) {
			    	temp = line;
			    	temp = temp.replaceAll("\\\\\\{\\$TODAY_DATE\\\\\\}", df_1.format(new Date()));
			    	temp = temp.replaceAll("\\\\\\{\\$MERCHANT_NAME\\\\\\}", m_case.getMerchant().getRegisteredName());
			    	temp = temp.replaceAll("\\\\\\{\\$ADDRESS_LINE1\\\\\\}", address);
			    	temp = temp.replaceAll("\\\\\\{\\$ADDRESS_LINE2\\\\\\}", address2);
			    	temp = temp.replaceAll("\\\\\\{\\$ADDRESS_LINE3\\\\\\}", address3);
			    	temp = temp.replaceAll("\\\\\\{\\$ADDRESS_LINE4\\\\\\}", address4);
			    	
			    	temp = temp.replaceAll("\\$POS_Visa_Off_us", (pos_visa_off_us.length() > 0 ? pos_visa_off_us + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$POS_Master_Off_us\\\\\\}", (pos_master_off_us.length() > 0 ? pos_master_off_us + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$POS_Visa_Debit\\\\\\}", (pos_visa_debit.length() > 0 ? pos_visa_debit + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$POS_Master_Debit\\\\\\}", (pos_master_debit.length() > 0 ? pos_master_debit + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$POS_Amex_Nett_Disc_Rate\\\\\\}", (pos_amex_nett_disc_rate.length() > 0 ? pos_amex_nett_disc_rate + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$POS_EFT_POS_ATM\\\\\\}", (pos_eft_pos_atm.length() > 0 ? pos_eft_pos_atm + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$POS_Maestro\\\\\\}", (pos_maestro.length() > 0 ? pos_maestro + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$POS_JCB\\\\\\}", (pos_jcb.length() > 0 ? pos_jcb + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$g1\\\\\\}", (pos_unionpay.length() > 0 ? pos_unionpay + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$DCC_Rebate\\\\\\}", (dcc_rebate.length() > 0 ? dcc_rebate + "%" : ""));
			    	
			    	temp = temp.replaceAll("\\\\\\{\\$MO_Visa_Off_Us\\\\\\}", (mo_visa_off_us.length() > 0 ? mo_visa_off_us + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$MO_Master_Off_us\\\\\\}", (mo_master_off_us.length() > 0 ? mo_master_off_us + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$MO_Visa_Debit\\\\\\}", (mo_visa_debit.length() > 0 ? mo_visa_debit + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$MO_Master_Debit\\\\\\}", (mo_master_debit.length() > 0 ? mo_master_debit + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$MO_Amex_Nett_Disc_Rate\\\\\\}", (mo_amex_nett_disc_rate.length() > 0 ? mo_amex_nett_disc_rate + "%" : ""));
			    	
			    	temp = temp.replaceAll("\\\\\\{\\$TO_Visa_Off_Us\\\\\\}", (to_visa_off_us.length() > 0 ? to_visa_off_us + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$TO_Master_Off_us\\\\\\}", (to_master_off_us.length() > 0 ? to_master_off_us + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$TO_Visa_Debit\\\\\\}", (to_visa_debit.length() > 0 ? to_visa_debit + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$TO_Master_Debit\\\\\\}", (to_master_debit.length() > 0 ? to_master_debit + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$TO_Amex_Nett_Disc_Rate\\\\\\}", (to_amex_nett_disc_rate.length() > 0 ? to_amex_nett_disc_rate + "%" : ""));
			    	
			    	temp = temp.replaceAll("\\\\\\{\\$RPS_Visa_Off_Us\\\\\\}", (rps_visa_off_us.length() > 0 ? rps_visa_off_us + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$RPS_Master_Off_us\\\\\\}", (rps_master_off_us.length() > 0 ? rps_master_off_us + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$RPS_Visa_Debit\\\\\\}", (rps_visa_debit.length() > 0 ? rps_visa_debit + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$RPS_Master_Debit\\\\\\}", (rps_master_debit.length() > 0 ? rps_master_debit + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$RPS_Amex_Nett_Disc_Rate\\\\\\}", (rps_amex_nett_disc_rate.length() > 0 ? rps_amex_nett_disc_rate + "%" : ""));
			    	
			    	temp = temp.replaceAll("\\\\\\{\\$EC_Visa_Off_Us\\\\\\}", (ec_visa_off_us.length() > 0 ? ec_visa_off_us + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$EC_Master_Off_us\\\\\\}", (ec_master_off_us.length() > 0 ? ec_master_off_us + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$EC_Visa_Debit\\\\\\}", (ec_visa_debit.length() > 0 ? ec_visa_debit + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$EC_Master_Debit\\\\\\}", (ec_master_debit.length() > 0 ? ec_master_debit + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$EC_Amex_Nett_Disc_Rate\\\\\\}", (ec_amex_nett_disc_rate.length() > 0 ? ec_amex_nett_disc_rate + "%" : ""));
			    	
			    	temp = temp.replaceAll("\\\\\\{\\$M2U_Visa_Off_Us\\\\\\}", (m2u_visa_off_us.length() > 0 ? m2u_visa_off_us + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$M2U_Master_Off_us\\\\\\}", (m2u_master_off_us.length() > 0 ? m2u_master_off_us + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$M2U_Visa_Debit\\\\\\}", (m2u_visa_debit.length() > 0 ? m2u_visa_debit + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$M2U_Master_Debit\\\\\\}", (m2u_master_debit.length() > 0 ? m2u_master_debit + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$M2U_Amex_Nett_Disc_Rate\\\\\\}", (m2u_amex_nett_disc_rate.length() > 0 ? m2u_amex_nett_disc_rate + "%" : ""));
			    	
			    	temp = temp.replaceAll("\\\\\\{\\$h1\\\\\\}", (e3_mdr.length() > 0 ? e3_mdr + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$h2\\\\\\}", (e3_min.length() > 0 ? "RM" + e3_min : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$h3\\\\\\}", (e3_max.length() > 0 ? "RM" + e3_max : ""));
			    	
			    	temp = temp.replaceAll("\\\\\\{\\$i1\\\\\\}", (e6_mdr.length() > 0 ? e6_mdr + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$i2\\\\\\}", (e6_min.length() > 0 ? "RM" + e6_min : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$i3\\\\\\}", (e6_max.length() > 0 ? "RM" + e6_max : ""));
			    	
			    	temp = temp.replaceAll("\\\\\\{\\$j1\\\\\\}", (e9_mdr.length() > 0 ? e9_mdr + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$j2\\\\\\}", (e9_min.length() > 0 ? "RM" + e9_min : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$j3\\\\\\}", (e9_max.length() > 0 ? "RM" + e9_max : ""));
			    	
			    	temp = temp.replaceAll("\\\\\\{\\$k1\\\\\\}", (e12_mdr.length() > 0 ? e12_mdr + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$k2\\\\\\}", (e12_min.length() > 0 ? "RM" + e12_min : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$k3\\\\\\}", (e12_max.length() > 0 ? "RM" + e12_max : ""));
			    	
			    	temp = temp.replaceAll("\\\\\\{\\$l1\\\\\\}", (e18_mdr.length() > 0 ? e18_mdr + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$l2\\\\\\}", (e18_min.length() > 0 ? "RM" + e18_min : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$l3\\\\\\}", (e18_max.length() > 0 ? "RM" + e18_max : ""));
			    	
			    	temp = temp.replaceAll("\\\\\\{\\$m1\\\\\\}", (e24_mdr.length() > 0 ? e24_mdr + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$m2\\\\\\}", (e24_min.length() > 0 ? "RM" + e24_min : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$m3\\\\\\}", (e24_max.length() > 0 ? "RM" + e24_max : ""));
			    	
			    	temp = temp.replaceAll("\\\\\\{\\$n1\\\\\\}", (e30_mdr.length() > 0 ? e30_mdr + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$n2\\\\\\}", (e30_min.length() > 0 ? "RM" + e30_min : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$n3\\\\\\}", (e30_max.length() > 0 ? "RM" + e30_max : ""));
			    	
			    	temp = temp.replaceAll("\\\\\\{\\$o1\\\\\\}", (e36_mdr.length() > 0 ? e36_mdr + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$o2\\\\\\}", (e36_min.length() > 0 ? "RM" + e36_min : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$o3\\\\\\}", (e36_max.length() > 0 ? "RM" + e36_max : ""));
			    	
			    	
			    	temp = temp.replaceAll("\\\\\\{\\$MERCHANT_NAME\\\\\\}", m_case.getMerchant().getRegisteredName());
			    	temp = temp.replaceAll("\\\\\\{\\$TERMINAL_DEPOSIT_WIRED\\\\\\}", c_outlet.getTrmDepositWired());
			    	temp = temp.replaceAll("\\$TERMINAL_RENTAL_DEPOSIT_WIRED", c_outlet.getTrmRentalDepositWired());
			    	temp = temp.replaceAll("\\$TERMINAL_RENTAL_ADVANCE", c_outlet.getTrmRentalAdvance());
			    	temp = temp.replaceAll("\\$TERMINAL_DEPOSIT_WIRELESS", c_outlet.getTrmDepositWireless());
			    	temp = temp.replaceAll("\\$TERMINAL_RENTAL_DEPOSIT_WIRELESS", c_outlet.getTrmRentalDepositWireless());
			    	
			    	temp = temp.replaceAll("\\\\\\{\\$TRF\\\\\\}", trf);
			    	temp = temp.replaceAll("\\$NO_OF_TERMINAL_WIRED", no_of_wired_terminal);
			    	temp = temp.replaceAll("\\$TOTAL_TRF_WIRED", trf_wired);
			    	temp = temp.replaceAll("\\$NO_OF_TERMINAL_WIRELESS", no_of_wireless_terminal);
			    	temp = temp.replaceAll("\\\\\\{\\$TOTAL_TRF_WIRELESS\\\\\\}", trf_wireless);
			    	
			    	/****************************************************************************************/
			    	
			    	temp = temp.replaceAll("\\\\\\{\\$a1\\\\\\}", (pos_mydebit_local.length() > 0 ? pos_mydebit_local + "%" : ""));

			    	temp = temp.replaceAll("\\\\\\{\\$b1\\\\\\}", (pos_visa_debit_prepaid_local.length() > 0 ? pos_visa_debit_prepaid_local + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$b2\\\\\\}", (mo_visa_debit_prepaid_local.length() > 0 ? mo_visa_debit_prepaid_local + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$b3\\\\\\}", (to_visa_debit_prepaid_local.length() > 0 ? to_visa_debit_prepaid_local + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$b4\\\\\\}", (rps_visa_debit_prepaid_local.length() > 0 ? rps_visa_debit_prepaid_local + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$b5\\\\\\}", (ec_visa_debit_prepaid_local.length() > 0 ? ec_visa_debit_prepaid_local + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$b6\\\\\\}", (m2u_visa_debit_prepaid_local.length() > 0 ? m2u_visa_debit_prepaid_local + "%" : ""));

			    	temp = temp.replaceAll("\\\\\\{\\$c1\\\\\\}", (pos_master_debit_prepaid_local.length() > 0 ? pos_master_debit_prepaid_local + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$c2\\\\\\}", (mo_master_debit_prepaid_local.length() > 0 ? mo_master_debit_prepaid_local + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$c3\\\\\\}", (to_master_debit_prepaid_local.length() > 0 ? to_master_debit_prepaid_local + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$c4\\\\\\}", (rps_master_debit_prepaid_local.length() > 0 ? rps_master_debit_prepaid_local + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$c5\\\\\\}", (ec_master_debit_prepaid_local.length() > 0 ? ec_master_debit_prepaid_local + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$c6\\\\\\}", (m2u_master_debit_prepaid_local.length() > 0 ? m2u_master_debit_prepaid_local + "%" : ""));

			    	
			    	temp = temp.replaceAll("\\\\\\{\\$d1\\\\\\}", (pos_visa_local.length() > 0 ? pos_visa_local + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$d2\\\\\\}", (mo_visa_local.length() > 0 ? mo_visa_local + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$d3\\\\\\}", (to_visa_local.length() > 0 ? to_visa_local + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$d4\\\\\\}", (rps_visa_local.length() > 0 ? rps_visa_local + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$d5\\\\\\}", (ec_visa_local.length() > 0 ? ec_visa_local + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$d6\\\\\\}", (m2u_visa_local.length() > 0 ? m2u_visa_local + "%" : ""));

			    	temp = temp.replaceAll("\\\\\\{\\$e1\\\\\\}", (pos_master_local.length() > 0 ? pos_master_local + "%" : ""));
			    	temp = temp.replaceAll("\\$e2", (mo_master_local.length() > 0 ? mo_master_local + "%" : ""));
			    	temp = temp.replaceAll("\\$e3", (to_master_local.length() > 0 ? to_master_local + "%" : ""));
			    	temp = temp.replaceAll("\\$e4", (rps_master_local.length() > 0 ? rps_master_local + "%" : ""));
			    	temp = temp.replaceAll("\\$e5", (ec_master_local.length() > 0 ? ec_master_local + "%" : ""));
			    	temp = temp.replaceAll("\\$e6", (m2u_master_local.length() > 0 ? m2u_master_local + "%" : ""));
			    	
			    	temp = temp.replaceAll("\\$f1", (pos_amex_local.length() > 0 ? pos_amex_local + "%" : ""));
			    	temp = temp.replaceAll("\\$f2", (mo_amex_local.length() > 0 ? mo_amex_local + "%" : ""));
			    	temp = temp.replaceAll("\\$f3", (to_amex_local.length() > 0 ? to_amex_local + "%" : ""));
			    	temp = temp.replaceAll("\\$f4", (rps_amex_local.length() > 0 ? rps_amex_local + "%" : ""));
			    	temp = temp.replaceAll("\\$f5", (ec_amex_local.length() > 0 ? ec_amex_local + "%" : ""));
			    	temp = temp.replaceAll("\\$f6", (m2u_amex_local.length() > 0 ? m2u_amex_local + "%" : ""));
			    	
			    	temp = temp.replaceAll("\\\\\\{\\$POS_Amex_Foreign\\\\\\}", (pos_amex_foreign.length() > 0 ? pos_amex_foreign + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$MO_Amex_Foreign\\\\\\}", (mo_amex_foreign.length() > 0 ? mo_amex_foreign + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$TO_Amex_Foreign\\\\\\}", (to_amex_foreign.length() > 0 ? to_amex_foreign + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$RPS_Amex_Foreign\\\\\\}", (rps_amex_foreign.length() > 0 ? rps_amex_foreign + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$EC_Amex_Foreign\\\\\\}", (ec_amex_foreign.length() > 0 ? ec_amex_foreign + "%" : ""));
			    	temp = temp.replaceAll("\\\\\\{\\$M2U_Amex_Foreign\\\\\\}", (m2u_amex_foreign.length() > 0 ? m2u_amex_foreign + "%" : ""));
			    	
			    	f_content += temp + "\r\n";
			    }
			    
			    r.close();
			    byte[] b= f_content.getBytes();
			    
				ServletOutputStream outStream = response.getOutputStream();
				
				response.setContentType("text/rtf");
				response.setContentLength(f_content.length());
				response.setHeader("Content-Disposition", "attachment; filename=\"MAP-letter-of-offer.rtf\"");
				
				
				outStream.write(b);
				outStream.close();
				
			    
			    return null;
				    
				
				
			} else {
				nextPage="not_authorized";
				return mapping.findForward(nextPage);
			}
			
	}
	
	public ActionForward vendor_pos_3(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.vendor_pos_3";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			if(request.getParameter("serial_no") != null) {
				String serial_no =  EncryptionHelper.decrypt(sanitize(request.getParameter("serial_no")));
				
			
				OutletFactory o = new OutletFactory();
				CaseOutlet c_outlet = o.getCaseOutletBySerialNo(serial_no);
				if(c_outlet == null){
					json_error("Failed to get Vendor from the serial no: " + serial_no, response);
					return null;
				}
				
				
				Casemast m_case = CasemastFactory.getCaseMast(c_outlet.getCaseId());
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
						
	
				String vendor_name = "";
				JSONObject vendor_arr = new JSONObject();
				
				if(request.getParameter("vendor_name") != null){
					vendor_name = URLDecoder.decode(request.getParameter("vendor_name"), "UTF-8");
				} 
				else if(c_outlet.getPosForm().length() > 0){
					JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getPosForm());
					
					vendor_arr = (JSONObject) obj.get("vendor_arr");
					vendor_name = c_outlet.getVendor_name();
				}
				
				if(vendor_name.equals("") == false){
					request.setAttribute("vendor_name", vendor_name);
				}
				
				request.setAttribute("vendor_arr", vendor_arr);
				
				if(vendor_name.equals("") == false){
					request.setAttribute("vendor_name", vendor_name);
				}
				
				c_outlet.loadInstallNotes(vendor_name);
				
				
				request.setAttribute("serial_no", serial_no);
				request.setAttribute("c_outlet", c_outlet);
				request.setAttribute("m_case", m_case);
				
				ArrayList<String> maybank_stock = new ArrayList<String>();
				ArrayList<String> esa_stock = new ArrayList<String>();
				
				maybank_stock.add("Maybank MPOS");
				maybank_stock.add("Nera (M) Sdn Bhd");
				maybank_stock.add("PAYSYS (M) Sdn Bhd");
				maybank_stock.add("IT Bizflow Sdn Bhd");
				maybank_stock.add("GHL Berhad ");
				maybank_stock.add("TM KIOSK");
				maybank_stock.add("OPENSYS");
				maybank_stock.add("LONGBOW");
				
				String esa_ref_no = c_outlet.getESARefNo();
				
				if(esa_ref_no != null && esa_ref_no.equals("") == false){
					esa_stock.add(esa_ref_no);
				}
				
				request.setAttribute("maybank_stock", maybank_stock);
				request.setAttribute("esa_stock", esa_stock);
				
				try {
					InputStream stream = NewAppAction.class.getResourceAsStream(CONFIG_FILE);
					if (stream != null){
						appCfg.load(stream);
					} else {
						System.out.println("NewAppAction.vendor_pos_3 Input Stream is NULL");
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				
				String http_scheme = appCfg.getProperty("HTTP_SCHEME");
				String host_domain = http_scheme + "://" + request.getServerName();
				
				if(request.getServerPort() != 80 && request.getServerPort() != 443){
					host_domain += ":" + request.getServerPort();
				}
				
				host_domain += request.getContextPath();
				
				request.setAttribute("host_domain", host_domain);
			}
			
			this.authorized(request);
			
			nextPage="not_authorized";
			if(this.iApp0 > 0){
				String s_arr[] = null;
				ArrayList<String> mod_arr = new ArrayList<String>();
				
				s_arr = NewAppAction.modVendorPosForm.split(",");
				for(String s : s_arr){
					mod_arr.add(s);
				}
				
				if(mod_arr.contains(this.iMod)) {
					nextPage="vendor_pos_3";
				}
			} 
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}
	
	public ActionForward vendor_pos(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.vendor_pos";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			this.authorized(request);
			
			nextPage="not_authorized";
			if(this.iApp0 > 0){
				String s_arr[] = null;
				ArrayList<String> mod_arr = new ArrayList<String>();
				
				s_arr = NewAppAction.modVendorPosForm.split(",");
				for(String s : s_arr){
					mod_arr.add(s);
				}
				
				if(mod_arr.contains(this.iMod)) {
					nextPage="vendor_pos";
				}
			} 
			
			if(!nextPage.equals("not_authorized") && request.getParameter("m_id") != null && request.getParameter("c_id") != null) {
				
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
				
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				
				OutletFactory o = new OutletFactory();
				ArrayList<CaseOutlet> c_outlets = o.getCaseOutlets(case_id);
				if(c_outlets == null){
					json_error(o.getMessage(), response);
					return null;
				}
			
				
				int outlet_id = 0;
				
				if(request.getParameter("o_id") != null) {
					outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("o_id")));
				}
				else if(c_outlets.size() > 0) {
					outlet_id = (int) c_outlets.get(0).getOutlet().getId();
				}
				
				
				CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
				String creatorName  = o.getCreatorName(case_id);
				
				if(c_outlet == null){
					System.out.println(o.getMessage());
					return null;
				}
				
				request.setAttribute("c_outlet", c_outlet);
				
				request.setAttribute("merchant_id", merchant_id);
				request.setAttribute("case_id", case_id);
				request.setAttribute("m_case", m_case);
				request.setAttribute("c_outlets", c_outlets);
				request.setAttribute("creator_name", creatorName);
				
				ArrayList<String> maybank_stock = new ArrayList<String>();
				ArrayList<String> esa_stock = new ArrayList<String>();
				
				maybank_stock.add("Maybank MPOS");
				maybank_stock.add("Nera (M) Sdn Bhd");
				maybank_stock.add("PAYSYS (M) Sdn Bhd");
				maybank_stock.add("IT Bizflow Sdn Bhd");
				maybank_stock.add("GHL Berhad ");
				maybank_stock.add("TM KIOSK");
				maybank_stock.add("OPENSYS");
				maybank_stock.add("LONGBOW");
				
				String esa_ref_no = c_outlet.getESARefNo();
				
				if(esa_ref_no != null && esa_ref_no.equals("") == false){
					esa_stock.add(esa_ref_no);
				}
				
				request.setAttribute("maybank_stock", maybank_stock);
				request.setAttribute("esa_stock", esa_stock);
				
				
				JSONObject vendor_arr = new JSONObject();
				String vendor_name = "";
				
				if(request.getParameter("vendor_name") != null){
					vendor_name = URLDecoder.decode(request.getParameter("vendor_name"), "UTF-8");
				} 
				else if(c_outlet.getPosForm().length() > 0){
					JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getPosForm());
					
					vendor_arr = (JSONObject) obj.get("vendor_arr");
					if(vendor_arr != null){
						for(Object s : vendor_arr.keySet()){
							vendor_name = String.valueOf(s);
							break;
						}
					}
				}
				
				if(vendor_name.equals("") == false){
					request.setAttribute("vendor_name", vendor_name);
				}
				
				request.setAttribute("vendor_arr", vendor_arr);
				
				
				try {
					InputStream stream = NewAppAction.class.getResourceAsStream(CONFIG_FILE);
					if (stream != null){
						appCfg.load(stream);
					} else {
						System.out.println("NewAppAction.vendor_pos Input Stream is NULL");
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				
				
				String http_scheme = appCfg.getProperty("HTTP_SCHEME");
				String host_domain = http_scheme + "://" + request.getServerName();
				
				if(request.getServerPort() != 80 && request.getServerPort() != 443){
					host_domain += ":" + request.getServerPort();
				}
				
				host_domain += request.getContextPath();
				
				request.setAttribute("host_domain", host_domain);
				
				
			} else {
				nextPage="not_authorized";
			}
			
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}
	
	
	public ActionForward appendix_dcc(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.appendix_dcc";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null) {
				
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
				int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("o_id")));
				
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				
				OutletFactory o = new OutletFactory();
				CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
				if(c_outlet == null){
					System.out.println(o.getMessage());
					return null;
				}
				
				request.setAttribute("c_outlet", c_outlet);
				
				request.setAttribute("merchant_id", merchant_id);
				request.setAttribute("case_id", case_id);
				request.setAttribute("m_case", m_case);
				
				
				try {
					InputStream stream = NewAppAction.class.getResourceAsStream(CONFIG_FILE);
					if (stream != null){
						appCfg.load(stream);
					} else {
						System.out.println("SubmitAppAction Input Stream is NULL");
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				
				String email_addr = appCfg.getProperty("dcc_email");
				
				request.setAttribute("email_addr", email_addr);
				
				this.authorized(request);
				
				nextPage="not_authorized";
				if(this.iApp0 > 0){
					nextPage="appendix_dcc";
				} 
				
			} else {
				nextPage="not_authorized";
			}
			
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}
	
	public ActionForward appendix_unionpay(ActionMapping mapping,
	    ActionForm form, HttpServletRequest request,
	    HttpServletResponse response) throws Exception {

	    final String PROG_ID="NewAppAction.appendix_unionpay";

	    System.out.println(PROG_ID + " : BEGIN");
	    HttpSession session = request.getSession(false);
	    
	    String nextPage = null;
	    
		//check session condition
		if (session == null){
			return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
		    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
		    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
		    if (DEBUG) System.out.println("... Javascript not enable");
		    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
		    if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
			    if (DEBUG) System.out.println("sessionstatus !=null 2");
	  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
	  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			return mapping.findForward(strFwd);
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(request.getParameter("m_id") != null && request.getParameter("c_id") != null) {
			
			int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
			int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
			int outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("o_id")));
			String vendor_name = request.getParameter("vendor_name");
			
			Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
			if(m_case == null){
				json_error(CasemastFactory.getMessage(), response);
				return null;
			}
			
			OutletFactory o = new OutletFactory();
			CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
			if(c_outlet == null){
				System.out.println(o.getMessage());
				return null;
			}
			
			request.setAttribute("c_outlet", c_outlet);
			
			request.setAttribute("merchant_id", merchant_id);
			request.setAttribute("case_id", case_id);
			request.setAttribute("vendor_name", vendor_name);
			request.setAttribute("m_case", m_case);
			
			
			try {
				InputStream stream = NewAppAction.class.getResourceAsStream(CONFIG_FILE);
				if (stream != null){
					appCfg.load(stream);
				} else {
					System.out.println("SubmitAppAction Input Stream is NULL");
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			String email_addr = appCfg.getProperty("unionpay_email");
			
			request.setAttribute("email_addr", email_addr);
			
			this.authorized(request);
			
			nextPage="not_authorized";
			if(this.iApp0 > 0){
				nextPage="appendix_unionpay";
			} 
			
		} else {
			nextPage="not_authorized";
		}
		
		
		request.setAttribute("view_access", this.viewAccess);
		
		return mapping.findForward(nextPage);
	}
	
	public ActionForward appendix_partner(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.appendix_partner";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null) {
				
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
				String partner_name = sanitize(request.getParameter("partner_name"));
				
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				
				OutletFactory o = new OutletFactory();
				ArrayList<CaseOutlet> c_outlets = o.getCaseOutlets(case_id);
				if(c_outlets == null){
					json_error(o.getMessage(), response);
					return null;
				}
			
				
				int outlet_id = 0;
				
				if(request.getParameter("o_id") != null) {
					outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("o_id")));
				}
				else if(c_outlets.size() > 0) {
					outlet_id = (int) c_outlets.get(0).getOutlet().getId();
				}
				
				
				CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
				if(c_outlet == null){
					System.out.println(o.getMessage());
					return null;
				}
				
				request.setAttribute("c_outlet", c_outlet);
				
				request.setAttribute("merchant_id", merchant_id);
				request.setAttribute("case_id", case_id);
				request.setAttribute("partner_name", partner_name);
				request.setAttribute("m_case", m_case);
				request.setAttribute("c_outlets", c_outlets);
				
				
				try {
					InputStream stream = NewAppAction.class.getResourceAsStream(CONFIG_FILE);
					if (stream != null){
						appCfg.load(stream);
					} else {
						System.out.println("SubmitAppAction Input Stream is NULL");
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				
				String email_addr = "";
				
				if(partner_name.equals("DINERS")) {
					email_addr = appCfg.getProperty("diners_email");
				}
				else if(partner_name.equals("AEON")) {
					email_addr = appCfg.getProperty("aeon_email");
				}
				else if(partner_name.equals("GENTING")) {
					email_addr = appCfg.getProperty("genting_email");
				}
				else if(partner_name.startsWith("Tag On - ")) {
					String bank_name = partner_name.substring(new String("Tag On - ").length());
					email_addr = appCfg.getProperty(bank_name.toLowerCase() + "_email");
				}
				else if(partner_name.startsWith("Vendor - ")) {
					c_outlet = (CaseOutlet) request.getAttribute("c_outlet");
					String vendor_name2 = partner_name.substring(new String("Vendor - ").length());
					
					JSONObject pos_form = (JSONObject) JSONValue.parse(c_outlet.getPosForm());
					JSONObject vendor_arr = new JSONObject();;
					if(pos_form.get("vendor_arr") != null){
						vendor_arr = (JSONObject) pos_form.get("vendor_arr");
						for(Object vName : vendor_arr.keySet()) {
							JSONObject vendor_details = (JSONObject) vendor_arr.get(vName);
							
							if(vendor_details.get("name").toString().equals(vendor_name2)) {
								email_addr = vendor_details.get("email").toString();
								break;
							}
						}
					}
				}
				
				request.setAttribute("email_addr", email_addr);
				
				this.authorized(request);
				
				nextPage="not_authorized";
				if(this.iApp0 > 0){
					nextPage="vendor_pos2";
				} 
				
			} else {
				nextPage="not_authorized";
			}
			
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}
	
	public ActionForward vendor_installation(ActionMapping mapping,
	    ActionForm form, HttpServletRequest request,
	    HttpServletResponse response) throws Exception {

	    final String PROG_ID="NewAppAction.vendor_installation";

	    System.out.println(PROG_ID + " : BEGIN");
	    HttpSession session = request.getSession(false);
	    
	    String nextPage = null;
	    
		//check session condition
		if (session == null){
			return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
		    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
		    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
		    if (DEBUG) System.out.println("... Javascript not enable");
		    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
		    if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
			    if (DEBUG) System.out.println("sessionstatus !=null 2");
	  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
	  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			return mapping.findForward(strFwd);
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		this.authorized(request);
		
		nextPage="not_authorized";
		if(this.iApp0 > 0){
			String s_arr[] = null;
			ArrayList<String> mod_arr = new ArrayList<String>();
			
			s_arr = NewAppAction.modVendorPosForm.split(",");
			for(String s : s_arr){
				mod_arr.add(s);
			}
			
			if(mod_arr.contains(this.iMod)) {
				nextPage="vendor_installation";
			}
		} 
		
		if(!nextPage.equals("not_authorized") && EncryptionHelper.decrypt(request.getParameter("m_id")) != null && EncryptionHelper.decrypt(request.getParameter("c_id")) != null) {
			int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
			int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
			
			Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
			if(m_case == null){
				json_error(CasemastFactory.getMessage(), response);
				return null;
			}
			
			
			OutletFactory o = new OutletFactory();
			ArrayList<CaseOutlet> c_outlets = o.getCaseOutlets(case_id);
			if(c_outlets == null){
				json_error(o.getMessage(), response);
				return null;
			}
		
			
			int outlet_id = 0;
			
			if(request.getParameter("o_id") != null) {
				outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("o_id")));
			}
			else if(c_outlets.size() > 0) {
				outlet_id = (int) c_outlets.get(0).getOutlet().getId();
			}
			
			
			CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
			if(c_outlet == null){
				System.out.println(o.getMessage());
				return null;
			}
			
			
			String vendor_name = "";
			
			if(request.getParameter("vendor_name") != null){
				vendor_name = request.getParameter("vendor_name");
			} else if(c_outlet.getPosForm().length() > 0){
				JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getPosForm());
				JSONObject vendor_arr = (JSONObject) obj.get("vendor_arr");
				
				if(vendor_arr != null){
					for(Object s : vendor_arr.keySet()){
						vendor_name = String.valueOf(s);
						break;
					}
				}
			}
			
			if(vendor_name.equals("") == false){
				request.setAttribute("vendor_name", vendor_name);
			}
			
			
			
			c_outlet.loadInstallNotes(vendor_name);
			
			
			request.setAttribute("c_outlet", c_outlet);
			
			request.setAttribute("merchant_id", merchant_id);
			request.setAttribute("case_id", case_id);
			request.setAttribute("m_case", m_case);
			request.setAttribute("c_outlets", c_outlets);
			
		} else {
			nextPage="not_authorized";
		}
		
		
		request.setAttribute("view_access", this.viewAccess);
		
		return mapping.findForward(nextPage);
	}
	
	public ActionForward terminal_vendor_installation(ActionMapping mapping,
	    ActionForm form, HttpServletRequest request,
	    HttpServletResponse response) throws Exception {

	    final String PROG_ID="NewAppAction.terminal_vendor_installation";

	    System.out.println(PROG_ID + " : BEGIN");
	    HttpSession session = request.getSession(false);
	    
	    String nextPage = null;
	    
		//check session condition
		if (session == null){
			return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
		}
//		if(!isTokenValid(request)){
//			System.out.println("Token validation failed!");
//			session.invalidate();
//			return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
//		}else{
//			resetToken(request);
//			System.out.println("Token validation passed!");
//		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
		    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
		    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
		    if (DEBUG) System.out.println("... Javascript not enable");
		    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
		    if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
			    if (DEBUG) System.out.println("sessionstatus !=null 2");
	  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
	  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			return mapping.findForward(strFwd);
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		if(request.getParameter("serial_no") != null) {
			String serial_no = sanitize(request.getParameter("serial_no"));
			
		
			OutletFactory o = new OutletFactory();
			CaseOutlet c_outlet = o.getCaseOutletBySerialNo(serial_no);
			if(c_outlet == null){
				json_error(o.getMessage(), response);
				return null;
			}
			
			
			Casemast m_case = CasemastFactory.getCaseMast(c_outlet.getCaseId());
			if(m_case == null){
				json_error(CasemastFactory.getMessage(), response);
				return null;
			}
					
			
			
			String vendor_name = "";
			
			if(c_outlet.getPosForm().length() > 0){
				JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getPosForm());
				JSONObject vendor_arr = (JSONObject) obj.get("vendor_arr");
				
				vendor_name = c_outlet.getVendor_name();
			}
			
			if(vendor_name.equals("") == false){
				request.setAttribute("vendor_name", vendor_name);
			}
			
			//c_outlet.loadInstallNotes(vendor_name);
			
			
			request.setAttribute("serial_no", serial_no);
			request.setAttribute("c_outlet", c_outlet);
			request.setAttribute("m_case", m_case);
		}
		
		
		this.authorized(request);
		
		nextPage="not_authorized";
		
		if(this.iApp4 > 0){
			nextPage="terminal_vendor_installation";
		} 
		
		request.setAttribute("view_access", this.viewAccess);
		
		return mapping.findForward(nextPage);
		
	}
	
	public ActionForward esa_pl(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.esa_pl";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			String mcc = "";
			
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null) {
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
				
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				
				OutletFactory o = new OutletFactory();
				ArrayList<CaseOutlet> c_outlets = o.getCaseOutlets(case_id);
				if(c_outlets == null){
					json_error(o.getMessage(), response);
					return null;
				}
			
				
				int outlet_id = 0;
				
				if(request.getParameter("o_id") != null) {
					outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("o_id")));
				}
				else if(c_outlets.size() > 0) {
					outlet_id = (int) c_outlets.get(0).getOutlet().getId();
				}
				
				
				if(outlet_id > 0){
					CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
					if(c_outlet == null){
						System.out.println(o.getMessage());
						return null;
					}
					
					request.setAttribute("c_outlet", c_outlet);
					
					if(c_outlet != null){
						if(c_outlet.getOutlet().getMDRRate().length() > 0){
							JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
							mcc= obj.get("22") == null ? "" : obj.get("22").toString();
						}
					}
				}
				
				InterchangeFactory i = new InterchangeFactory();
				Interchange i_mcccode = i.getMccRate(mcc);
				if(i_mcccode == null){
					i_mcccode = i.getMccRate("0");
				}	
				
				request.setAttribute("i_mcccode", i_mcccode);			
				request.setAttribute("merchant_id", merchant_id);
				request.setAttribute("case_id", case_id);
				request.setAttribute("m_case", m_case);
				request.setAttribute("c_outlets", c_outlets);
				
				this.authorized(request);
				
				nextPage="not_authorized";
				
				if(this.iApp0 > 0){
					nextPage="esa_pl";
				} 
				
			} else {
				nextPage="not_authorized";
			}
			
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}
	
	public ActionForward non_esa_pl(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.non_esa_pl";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			String mcc = "";
			
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null) {
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
				
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				
				OutletFactory o = new OutletFactory();
				ArrayList<CaseOutlet> c_outlets = o.getCaseOutlets(case_id);
				if(c_outlets == null){
					json_error(o.getMessage(), response);
					return null;
				}
			
				
				int outlet_id = 0;
				
				if(request.getParameter("o_id") != null) {
					outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("o_id")));
				}
				else if(c_outlets.size() > 0) {
					outlet_id = (int) c_outlets.get(0).getOutlet().getId();
				}
				
				
				if(outlet_id > 0){
					CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
					if(c_outlet == null){
						System.out.println(o.getMessage());
						return null;
					}
					
					request.setAttribute("c_outlet", c_outlet);
					
					if(c_outlet != null){
						if(c_outlet.getOutlet().getMDRRate().length() > 0){
							JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
							mcc= obj.get("22") == null ? "" : obj.get("22").toString();
						}
					}
				}
				
				InterchangeFactory i = new InterchangeFactory();
				Interchange i_mcccode = i.getMccRate(mcc);
				if(i_mcccode == null){
					i_mcccode = i.getMccRate("0");

				}	
				
				request.setAttribute("i_mcccode", i_mcccode);			
				request.setAttribute("merchant_id", merchant_id);
				request.setAttribute("case_id", case_id);
				request.setAttribute("m_case", m_case);
				request.setAttribute("c_outlets", c_outlets);
				
				this.authorized(request);
				
				nextPage="not_authorized";
				
				if(this.iApp0 > 0){
					nextPage="non_esa_pl";
				} 
				
			} else {
				nextPage="not_authorized";
			}
			
			System.out.println("OKOKOK");
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}

	public ActionForward esa_ezypay(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.esa_ezypay";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null) {
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
			
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				
				OutletFactory o = new OutletFactory();
				ArrayList<CaseOutlet> c_outlets = o.getCaseOutlets(case_id);
				if(c_outlets == null){
					json_error(o.getMessage(), response);
					return null;
				}
			
				
				int outlet_id = 0;
				
				if(request.getParameter("o_id") != null) {
					outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("o_id")));
				}
				else if(c_outlets.size() > 0) {
					outlet_id = (int) c_outlets.get(0).getOutlet().getId();
				}
				
				
				if(outlet_id > 0){
					CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
					if(c_outlet == null){
						System.out.println(o.getMessage());
						return null;
					}
					
					request.setAttribute("c_outlet", c_outlet);
				}
				
				
				
				request.setAttribute("merchant_id", merchant_id);
				request.setAttribute("case_id", case_id);
				request.setAttribute("m_case", m_case);
				request.setAttribute("c_outlets", c_outlets);
				
				
				this.authorized(request);
				
				//System.out.println(this.authorized(request));
				
				
				nextPage="not_authorized";
				
				if(this.iApp0 > 0){
					nextPage="esa_ezypay";
				} 
				
				
			} else {
				nextPage="not_authorized";
			}
			
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}
	public ActionForward non_esa_ezypay(ActionMapping mapping,
		    ActionForm form, HttpServletRequest request,
		    HttpServletResponse response) throws Exception {

		    final String PROG_ID="NewAppAction.non_esa_ezypay";

		    System.out.println(PROG_ID + " : BEGIN");
		    HttpSession session = request.getSession(false);
		    
		    String nextPage = null;
		    
			//check session condition
			if (session == null){
				return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			}

			// browser javasript is not enable
			if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			    String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			    session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			    if (DEBUG) System.out.println("... Javascript not enable");
			    return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			}
			String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
			SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
			
			String strFwd = "";
			if (oSecUserDao == null){
				strFwd ="sessionError";
			}
			else
			{
				
			}
			if (sessionstatus != null){
			    if (DEBUG) System.out.println("sessionstatus !=null");
				if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
					//This is from refresh button.. set session expires.
				    if (DEBUG) System.out.println("sessionstatus !=null 2");
		  		    String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
		  		    session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
					return mapping.findForward(Constants.KEY_ACTION_LOGOUT);

				}
			}
			else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
				
				return mapping.findForward(strFwd);
		
			}
			
			
			/********************************************************************************/
			/* Custom code starts here */
			
			if(request.getParameter("m_id") != null && request.getParameter("c_id") != null) {
				int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
				int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
			
				Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
				if(m_case == null){
					json_error(CasemastFactory.getMessage(), response);
					return null;
				}
				
				
				OutletFactory o = new OutletFactory();
				ArrayList<CaseOutlet> c_outlets = o.getCaseOutlets(case_id);
				if(c_outlets == null){
					json_error(o.getMessage(), response);
					return null;
				}
			
				
				int outlet_id = 0;
				
				if(request.getParameter("o_id") != null) {
					outlet_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("o_id")));
				}
				else if(c_outlets.size() > 0) {
					outlet_id = (int) c_outlets.get(0).getOutlet().getId();
				}
				
				
				if(outlet_id > 0){
					CaseOutlet c_outlet = o.getCaseOutlet(case_id, outlet_id);
					if(c_outlet == null){
						System.out.println(o.getMessage());
						return null;
					}
					
					request.setAttribute("c_outlet", c_outlet);
				}
				
				
				
				request.setAttribute("merchant_id", merchant_id);
				request.setAttribute("case_id", case_id);
				request.setAttribute("m_case", m_case);
				request.setAttribute("c_outlets", c_outlets);
				
				this.authorized(request);
				
				//System.out.println(this.authorized(request));
				
				
				nextPage="not_authorized";
				
				if(this.iApp0 > 0){
					nextPage="non_esa_ezypay";
				} 
				
				
			} else {
				nextPage="not_authorized";
			}
			
			
			request.setAttribute("view_access", this.viewAccess);
			
			return mapping.findForward(nextPage);
	}

	public ActionForward print_case(ActionMapping mapping,
		ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		final String PROG_ID="SubmitAppAction.print_case";

		System.out.println(PROG_ID + " : BEGIN");
		HttpSession session = request.getSession(false);
		
		//String nextPage = null;
		
		//check session condition
		if (session == null){
			//return mapping.findForward(Constants.KEY_ACTION_SESSION_ERR);
			json_error("Session not found.", response);
			return null;
		}

		// browser javasript is not enable
		if (request.getParameter(Constants.PARAM_JS_ENABLE) != null && request.getParameter(Constants.PARAM_JS_ENABLE).equals("no") ) {
			String actionMsg = ConfigManager.getInstance().get(Constants.MSG_ERROR_JAVASCRIPT_NOT_ENABLE);
			session.setAttribute(Constants.LOGON_ERR_MSG, actionMsg);
			if (DEBUG) System.out.println("... Javascript not enable");
			//return mapping.findForward(Constants.KEY_ACTION_MAPPING_NOSCRIPT);
			json_error("Javascript not enabled.", response);
			return null;
		}
		String sessionstatus = (String) session.getAttribute(Constants.VISIT_STATUS);
		SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);// read user session time
		
		String strFwd = "";
		if (oSecUserDao == null){
			strFwd ="sessionError";
		}
		else
		{
			
		}
		if (sessionstatus != null){
			if (DEBUG) System.out.println("sessionstatus !=null");
			if ((sessionstatus.equals(Constants.VISIT_STATUS_VISITED)) || (session.isNew())){
				//This is from refresh button.. set session expires.
				if (DEBUG) System.out.println("sessionstatus !=null 2");
				String errMsg = ConfigManager.getInstance().get(Constants.MSG_LOGON_ERR_LOGOUT_ACTIVE_SESSION);
				session.setAttribute(Constants.LOGON_ERR_MSG, errMsg);
				//return mapping.findForward(Constants.KEY_ACTION_LOGOUT);
				
				json_error("sessionstatus !=null 2", response);
				return null;

			}
		}
		else if (oSecUserDao == null){// if the session expire, it will bring user to timeout screen
			
			//return mapping.findForward(strFwd);
			json_error("Your session has expired", response);
			return null;
	
		}
		
		
		/********************************************************************************/
		/* Custom code starts here */
		
		int case_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("c_id")));
		int merchant_id = Integer.parseInt(EncryptionHelper.decrypt(request.getParameter("m_id")));
		
		String strEMerchant = (String) session.getAttribute(Constants.MERCHANT_KEY);
  		
		
		Casemast m_case = CasemastFactory.getCaseMast(oSecUserDao.getGroupCode(), case_id);
		if(m_case == null){
			json_error(CasemastFactory.getMessage(), response);
			return null;
		}
		
		m_case.loadHistories(strEMerchant, 1);
		m_case.loadHistories(strEMerchant, 2);
		m_case.loadOutlets();
		
		
		ArrayList<SecGroupsDao> groupList = this.userGroupList(request);
		TreeMap<String, ArrayList<SecUserDao>> groupUsers = new TreeMap<String, ArrayList<SecUserDao>>();
		
		for(SecGroupsDao ug : groupList){
			ArrayList<SecUserDao> userList = new ArrayList<SecUserDao>();
			if ((strEMerchant != null) && (!strEMerchant.equals(""))){
				userList = SecUsersHome.getInstance().findSecGroupUserList(strEMerchant, ug.getGroupCode());
			}
			
			groupUsers.put(ug.getGroupCode(), userList);
		}
		
		
		
		request.setAttribute("groupList", groupList);
		request.setAttribute("groupUsers", groupUsers);
		request.setAttribute("m_case", m_case);
		request.setAttribute("merchant_id", merchant_id);
		request.setAttribute("case_id", case_id);
		
		
		String nextPage = "print_case";
		return mapping.findForward(nextPage);
		
	}
}
